const app = getApp()
var api = require('../../../utils/api.js')
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nikename: '', //搜索好友名称
    list: [],
    isSearched:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  inputFriend: function(e) {
    this.setData({
      nikename: e.detail.value
    })
  },

  search: function() {
    var that = this;
    var nikename = that.data.nikename;
    if(nikename.length==0){
      util.showError('请先输入搜索内容');
      return;
    }

    api.POST({
        params: {
          nikename: nikename
        },
        url: app.globalData.base_url + 'askWine/searchUser',
        success: function(res) {
          if (util.isEmpty(res.data.code)) {
              if(res.data.data.length>0){
                that.setData({
                  list: res.data.data
                })
              }else{
                that.setData({
                  list: []
                })
              }
          } else {
            util.showError(res.data.message);
          }
          that.setData({
            isSearched: true
          })
        },
        fail() {
          util.showError("网络错误");
        }
    })
},

  UserWineList:function(e){
    var user = e.currentTarget.dataset.user;
    wx.navigateTo({
      url: '/play/pages/friendWine/friendWine?uid=' + user.uid + '&userName=' + user.nickname,
    })
  },
  friendList:function(){
    wx.navigateTo({
      url: '/play/pages/myFriend/myFriend'
    })
  },
  onShareAppMessage: function (res) {
    var that = this;
    var share_uid = wx.getStorageSync('accountInfo').uid;
    var nickname = wx.getStorageSync('accountInfo').nickname;
    if (res.from === 'button') {
      // 来自页面内转发按钮
      return {
        title:nickname + '向您分享了飘香酒掌柜小程序',
        path: '/pages/index/index?share_uid=' + share_uid,
        imageUrl: '/images/share.jpg',
        success: function (res) {
          // 转发成功
        },
        fail: function (res) {
          // 转发失败
        }
      }
    }
  },
})